/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        queue<Node*> queue;
        vector<vector<int>> rst;

        if(root != nullptr) queue.push(root);

        while(queue.empty() == false){
            int length = queue.size();
            vector<int> rstLevel;
            for(int i = 0; i < length; ++i){
                Node* node = queue.front();
                rstLevel.push_back(node->val);

                for(auto node : node->children){
                    queue.push(node);
                }

                queue.pop();
            }

            rst.push_back(rstLevel);
        }

        return rst;
    }
};